package com.siterwell.push.mongodao;

import com.siterwell.push.entity.JPushLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class MongoJpushLogDao {
    @Autowired
    private MongoTemplate mongoTemplate;

    //批量导入数据
    public void saveJpushLogs(List<JPushLog> list){
        mongoTemplate.insert(list,JPushLog.class);
     }

     public void saveJpushLog(JPushLog jPushLog){
         mongoTemplate.save(jPushLog);
     }


    public JPushLog getSinglePushLog(long msg_id){
        Query query = new Query(Criteria.where("msg_id").is(msg_id));
        query.with(new Sort(Sort.Direction.DESC,"createtime"));
        return mongoTemplate.findOne(query,JPushLog.class);
    }


    public List<JPushLog> getPushLog(long msg_id){
        Query query = new Query(Criteria.where("msg_id").is(msg_id));
        query.with(new Sort(Sort.Direction.DESC,"createtime"));
        return mongoTemplate.find(query,JPushLog.class);
    }

}
